from django.db import models


class AliAuthUser(models.Model):
    '''支付宝用户'''

    user_id = models.CharField(verbose_name='用户id', max_length=16)

    class Meta:
        db_table = "tb_ali_auth_user"
        verbose_name = '支付宝用户'
        verbose_name_plural = verbose_name


class AliDiscountCouponWhiteTable(models.Model):
    '''活动参与白名单'''

    mobile = models.CharField(max_length=11, verbose_name='手机号')
    alidiscountcoupon = models.ForeignKey('vouchers.AliDiscountCoupon', verbose_name='活动', on_delete=models.CASCADE)

    class Meta:
        db_table = "tb_ali_discount_coupon_white_table"
        verbose_name = '活动参与白名单'
        verbose_name_plural = verbose_name


class AliDiscountCoupon(models.Model):
    '''优惠券信息'''

    COUPON_TYPE_CHOICES = (
        (1, '银行卡支付立减'),
        (2, '支付宝满减券'),
        (3, '首绑有礼'),
        (4, '多刷有礼'),
        (5, '饿了么场景营销'),
        (6, '商品抵扣券'),
        (7, '免充值券'),
        (8, '微信满减券'),
        (9, '商家满减券'),
        (10, '美团满减券'),
        (11, '支付宝营销抽奖')
    )

    COUPON_TYPE_ENUM = {
        'DISCOUNT': 1,
        'CHANNEL_COMMON_VOUCHER': 2,
        'FIRST_BIND_CARD_GIFT': 3,
        'ELEME': 5,
        'MORE_USE_CARD_GIFT': 4
    }

    COUPON_STATUS_CHOICES = (
        (1, '进行中'),
        (2, '已结束'),
        (3, '未开始'),
        (4, '已暂停')
    )

    COUPON_CHANNEL_CHOICES = (
        (1, '支付宝'),
        (2, '微信'),
        (3, '商家'),
        (5, '美团')
    )

    IS_NEED_AUTH_CHOICES = (
        (0, '否'),
        (1, '是')
    )

    IS_WHITE_CHOICES = (
        (0, '否'),
        (1, '是')
    )

    IS_UNION_CHOICES = (
        (0, '否'),
        (1, '是')
    )

    COUPON_WAY_CHOICES = (
        (1, '员工派券(固定)'),
        (2, '公开派券'),
        (3, '限时活动'),
        (4, '员工派券(共享)'),
        (5, 'API派券'),
        (6, '定制活动'),
        (7, '公开派券(多码)'),
        (8, '公开派券(手机银行)'),
        (9, '满额立减'),
        (10, '随机立减')
    )

    SYN_STATUS_CHOICES = (
        (0, '未同步'),
        (1, '已同步'),
        (2, '同步中')
    )

    IS_USE_PATH_CHOICES = (
        (0, '否'),
        (1, '是')
    )

    IS_SELF_CHOICES = (
        (0, '否'),
        (1, '是')
    )

    IS_CHECK_IDENTITY_CHOICES = (
        (0, '否'),
        (1, '是')
    )

    IS_PSBC_CARD_CHOICES = (
        (0, '否'),
        (1, '是')
    )

    IS_LOGIN_ID_CHOICES = (
        (0, '否'),
        (1, '是')
    )

    IS_KEGUAN_CHOICES = (
        (0, '否'),
        (1, '是')
    )

    USAGE_SCEBARIO_CHOICES = (
        (1, '指定商户可用'),
        (2, '全场景支付可用'),
        (3, '线上指定会场可用')
    )

    user = models.ForeignKey('users.User', verbose_name='添加人', on_delete=models.CASCADE)
    template_id = models.CharField(verbose_name='券模板ID', max_length=32, unique=True)
    activity_name = models.CharField(verbose_name='券模板名称', max_length=64)
    floor_amount = models.CharField(verbose_name='使用门槛', max_length=32)
    brand_name = models.CharField(verbose_name='品牌信息', max_length=32)
    activity_valid_period = models.CharField(verbose_name='活动的有效期', max_length=128)
    activity_description = models.TextField(verbose_name='活动使用说明')
    create_time = models.DateTimeField(verbose_name='添加时间', auto_now_add=True)
    publish_start_time = models.DateTimeField(verbose_name='发放开始时间')
    publish_end_time = models.DateTimeField(verbose_name='发放开始时间')
    max_number = models.IntegerField(verbose_name='限领最大数', default=1)
    send_count = models.IntegerField(verbose_name='已领取数量', default=0)
    use_count = models.IntegerField(verbose_name='已使用数量', default=0)
    remain_number = models.IntegerField(verbose_name='剩余数量', default=0)
    name = models.CharField(verbose_name='活动名称', max_length=128, null=True, blank=True)
    max_number_by_day = models.IntegerField(verbose_name='单天发放上限个数', help_text='单天发放上限个数', null=True, blank=True)
    max_number_by_user = models.IntegerField(verbose_name='单天发放上限个数', help_text='单天发放上限个数', null=True, blank=True)
    coupon_type = models.SmallIntegerField(verbose_name='优惠券类型', choices=COUPON_TYPE_CHOICES, default=1, blank=True)
    coupon_channel = models.SmallIntegerField(verbose_name='优惠券类型', choices=COUPON_CHANNEL_CHOICES, default=1, blank=True)
    amount = models.DecimalField(verbose_name='券核销/退款金额(元)', max_digits=10, decimal_places=2, default=0)
    transaction_minimum = models.DecimalField(verbose_name='门槛(元)', max_digits=10, decimal_places=2, default=0)
    coupon_status = models.SmallIntegerField(verbose_name='活动状态', choices=COUPON_STATUS_CHOICES, default=1, blank=True)
    is_need_auth = models.SmallIntegerField(verbose_name='是否需要认证', choices=IS_NEED_AUTH_CHOICES, default=1, blank=True)
    coupon_way = models.SmallIntegerField(verbose_name='派券类型', choices=COUPON_WAY_CHOICES, default=1, blank=True)
    is_white = models.SmallIntegerField(verbose_name='是否白名单派发', choices=IS_WHITE_CHOICES, default=0, blank=True)
    level = models.ForeignKey('users.Level', verbose_name='层级', on_delete=models.SET_NULL, null=True, blank=True)
    platform = models.ForeignKey('activities.Channel', verbose_name='所属平台', on_delete=models.SET_NULL, null=True, blank=True)
    available_merchants = models.CharField(verbose_name='参与活动商户说明', max_length=128, null=True, blank=True)
    is_union = models.SmallIntegerField(verbose_name='是否友商联盟', choices=IS_UNION_CHOICES, default=0, blank=True)
    start_enable_time = models.DateTimeField(verbose_name='限时活动生效时间', null=True, blank=True)
    end_enable_time = models.DateTimeField(verbose_name='限时活动失效时间', null=True, blank=True)
    last_update_time = models.DateTimeField(verbose_name='限时活动失效时间', null=True, blank=True)
    syn_status = models.SmallIntegerField(verbose_name='同步可用商户状态', choices=SYN_STATUS_CHOICES, default=0, blank=True)
    remark = models.TextField(verbose_name='备注', null=True, blank=True)
    distribution_platform = models.ForeignKey('vouchers.AliDiscountCouponDistributionPlatform', verbose_name='派发平台', on_delete=models.SET_NULL, null=True, blank=True)
    drawdown_platform = models.ForeignKey('vouchers.AliDiscountCouponDistributionPlatform', verbose_name='派发平台', on_delete=models.SET_NULL, null=True, blank=True, related_name='drawdown_platform_set')
    use_amount = models.DecimalField(verbose_name='券核销/退款金额(元)', max_digits=10, decimal_places=2, default=0)
    wyh_last_update_time = models.DateTimeField(verbose_name='微邮惠最后同步时间', null=True, blank=True)
    fn_order_id = models.CharField(verbose_name='赋能订单号', max_length=8, null=True, blank=True)
    is_use_path = models.SmallIntegerField(verbose_name='是否跳转平台使用', choices=IS_USE_PATH_CHOICES, null=True, blank=True)
    use_path = models.CharField(verbose_name='跳转路径', null=True, blank=True, max_length=64)
    use_appid = models.CharField(verbose_name='跳转appid', null=True, blank=True, max_length=64)
    is_self = models.SmallIntegerField(verbose_name='是否跳转平台使用', choices=IS_SELF_CHOICES, null=True, blank=True)
    goods_tag = models.CharField(verbose_name='优惠标识', null=True, blank=True, max_length=32)
    is_check_identity = models.SmallIntegerField(verbose_name='是否限制内部员工', choices=IS_CHECK_IDENTITY_CHOICES, null=True, blank=True)
    banner_short = models.ImageField(verbose_name='banner_log_short', null=True, blank=True)
    banner_long = models.ImageField(verbose_name='banner_log_long', null=True, blank=True)
    is_synchronization = models.SmallIntegerField(verbose_name='是否同步', choices=IS_CHECK_IDENTITY_CHOICES, null=True, blank=True)
    activity_zone_qrcode = models.ImageField(verbose_name='活动专区入口', null=True, blank=True)
    is_psbc_card = models.SmallIntegerField(verbose_name='是否绑定邮储卡', choices=IS_PSBC_CARD_CHOICES, default=0)
    product_no = models.CharField(verbose_name='好礼汇活动id', max_length=32, null=True, blank=True)
    is_login_id = models.SmallIntegerField(verbose_name='微信端领取是否输入支付宝账号', choices=IS_PSBC_CARD_CHOICES, default=0)
    is_keguan = models.SmallIntegerField(verbose_name='是否推送客管系统', choices=IS_KEGUAN_CHOICES, default=0)
    pushEventIds = models.CharField(verbose_name='营销事件ID', max_length=256, null=True, blank=True)
    usage_scenario = models.SmallIntegerField(verbose_name='使用场景', choices=USAGE_SCEBARIO_CHOICES, null=True, blank=True)

    class Meta:
        db_table = "tb_ali_discount_coupon"
        verbose_name = '优惠券信息'
        verbose_name_plural = verbose_name


class AliDiscountCouponMerchant(models.Model):
    '''活动所属商户'''

    alidiscountcoupon = models.ForeignKey('vouchers.AliDiscountCoupon', verbose_name='活动', on_delete=models.CASCADE)
    merchant = models.ForeignKey('merchants.Merchant', verbose_name='所属商户', on_delete=models.SET_NULL, null=True, blank=True)
    common_qrcode = models.ImageField(verbose_name='普码', null=True, blank=True)
    sub_mchid = models.CharField(verbose_name='间连商户号', max_length=16, null=True, blank=True)
    channel = models.ForeignKey('activities.Channel', verbose_name='所属通道', on_delete=models.SET_NULL, null=True, blank=True)

    class Meta:
        db_table = "tb_ali_discount_coupon_merchant"
        verbose_name = '活动所属商户'
        verbose_name_plural = verbose_name


class AliDiscountCouponGoodsAvailable(models.Model):
    '''可使用商品'''

    goods = models.ForeignKey('goods.Goods', on_delete=models.CASCADE, verbose_name='商品')
    launched_goods = models.ForeignKey('goods.LaunchedGoods', on_delete=models.SET_NULL, verbose_name='上架商品', null=True, blank=True)
    alidiscountcoupon = models.ForeignKey('vouchers.AliDiscountCoupon', verbose_name='活动', on_delete=models.CASCADE)
    alidiscountcoupon_level = models.ForeignKey('vouchers.AliDiscountCouponLevel', verbose_name='所属地市活动', on_delete=models.SET_NULL, null=True, blank=True)

    class Meta:
        db_table = 'tb_ali_discount_coupon_goods_available'
        verbose_name = '可使用商品'
        verbose_name_plural = verbose_name


class AliDiscountCouponChannelCommonVoucher(models.Model):
    '''通用渠道红包优惠券详情'''

    BANKCARD_TYPE_CHOICES = (
        (1, '信用卡'),
        (2, '借记卡'),
        (3, '信用卡,借记卡'),
        (4, '不限制')
    )

    BANKCARD_TYPE_ENUM = {
        'CREDIT': 1,
        'DEBIT': 2,
        'DEBIT_CREDIT': 3
    }

    DISCOUNT_TYPE_CHOICES = (
        (1, '定额满减'),
        (2, '随机满减'),
        (3, '免费兑换')
    )

    DISCOUNT_TYPE_ENUM = {
        'reduce': 1,
        'random': 2
    }

    USE_TIME_TYPE_CHOICES = (
        (1, '领取后'),
        (2, '固定时间段'),
        (3, '立即生效'),
        (4, '次日凌晨生效')
    )

    USE_TIME_TYPE_ENUM = {
        'RELATIVE': 1,
        'ABSOLUTELY': 2,
        'NOW': 3,
        'NEXT_DAY_ZERO_CLOCK': 4
    }

    JOIN_LIMIT_CHOICES = (
        (1, '限制'),
        (2, '不限制')
    )

    JOIN_LIMIT_ENUM = {
        'Y': 1,
        'N': 2
    }

    alidiscountcoupon = models.OneToOneField(AliDiscountCoupon, verbose_name='所属地市活动', on_delete=models.CASCADE)
    bankcard_type = models.SmallIntegerField(verbose_name='指定卡种可用', choices=BANKCARD_TYPE_CHOICES, default=1, blank=True)
    discount_type = models.SmallIntegerField(verbose_name='优惠方式', choices=DISCOUNT_TYPE_CHOICES, default=1, blank=True)
    principal_name = models.CharField(verbose_name='归属银行', max_length=32)
    biz_scene = models.ForeignKey('vouchers.AliBizScene', verbose_name='限制使用场景', on_delete=models.CASCADE)
    usetime_type = models.SmallIntegerField(verbose_name='可用时间', choices=USE_TIME_TYPE_CHOICES, default=1, blank=True)
    start_fixed_time = models.DateTimeField(verbose_name='生效时间', null=True, blank=True)
    end_fixed_time = models.DateTimeField(verbose_name='失效时间', null=True, blank=True)
    invalid_day = models.IntegerField(verbose_name='有效期', null=True, blank=True)
    join_limit_by_bay = models.SmallIntegerField(verbose_name='频率限制', choices=JOIN_LIMIT_CHOICES, default=1, blank=True)
    join_limit_by_user = models.SmallIntegerField(verbose_name='参与限制', choices=JOIN_LIMIT_CHOICES, default=1, blank=True)
    join_limit_by_bay_count = models.IntegerField(verbose_name='每人每天领取个数限制', null=True, blank=True)
    join_limit_by_user_count = models.IntegerField(verbose_name='活动期间每个用户可参与限制', null=True, blank=True)
    budget_amount = models.DecimalField(verbose_name='总预算(元)', max_digits=10, decimal_places=2, default=0)
    distributed_limit_by_time = models.SmallIntegerField(verbose_name='派发限时', choices=JOIN_LIMIT_CHOICES, default=2, blank=True)
    join_limit_by_location = models.SmallIntegerField(verbose_name='地理位置参与限制', choices=JOIN_LIMIT_CHOICES, default=2, blank=True)

    class Meta:
        db_table = "tb_ali_discount_coupon_channel_common_voucher"
        verbose_name = '通用渠道红包优惠券详情'
        verbose_name_plural = verbose_name


class AliDiscountCouponJoinLimitLocation(models.Model):
    '''地理位置参与限制'''

    ali_discount_coupon_common_voucher = models.ForeignKey('vouchers.AliDiscountCouponChannelCommonVoucher', verbose_name='优惠券详情', on_delete=models.CASCADE)
    longitude_begin = models.DecimalField(verbose_name='经度(起)', max_digits=10, decimal_places=6, default=0)
    longitude_end = models.DecimalField(verbose_name='经度(止)', max_digits=10, decimal_places=6, default=0)
    latitude_begin = models.DecimalField(verbose_name='纬度(起)', max_digits=10, decimal_places=6, default=0)
    latitude_end = models.DecimalField(verbose_name='纬度(止)', max_digits=10, decimal_places=6, default=0)
    level = models.ForeignKey('users.Level', verbose_name='地市', on_delete=models.SET_NULL, null=True, blank=True)

    class Meta:
        db_table = "tb_ali_discount_coupon_join_limit_by_location"
        verbose_name = '地理位置参与限制'
        verbose_name_plural = verbose_name


class AliDiscountCouponDistributedLimit(models.Model):
    '''优惠券派发时间限制'''

    ali_discount_coupon_common_voucher = models.ForeignKey('vouchers.AliDiscountCouponChannelCommonVoucher', verbose_name='优惠券详情', on_delete=models.CASCADE)
    weeks = models.CharField(verbose_name='每周', max_length=64)
    start_enable_time = models.DateTimeField(verbose_name='生效时间')
    end_enable_time = models.DateTimeField(verbose_name='失效时间')

    class Meta:
        db_table = "tb_ali_discount_coupon_distributed_limit"
        verbose_name = '优惠券派发时间限制'
        verbose_name_plural = verbose_name


class AliDiscountCouponLevel(models.Model):
    '''活动分配记录'''

    IS_AUTH_CHOICES = (
        (0, '无派发权限'),
        (1, '有派发权限')
    )

    level = models.ForeignKey('users.Level', verbose_name='层级', on_delete=models.CASCADE)
    activity = models.ForeignKey('vouchers.AliDiscountCoupon', verbose_name='活动', on_delete=models.CASCADE)
    max_number = models.IntegerField(verbose_name='限领最大数', default=0)
    take_number = models.IntegerField(verbose_name='占用领取数量', default=0)
    remain_number = models.IntegerField(verbose_name='剩余数量', default=0)
    use_number = models.IntegerField(verbose_name='已核销数量', default=0)
    receive_number = models.IntegerField(verbose_name='已领取数量', default=0)
    common_url = models.CharField(verbose_name='链接', max_length=128, null=True, blank=True)
    common_qrcode = models.ImageField(verbose_name='普码', null=True, blank=True)
    identify = models.CharField(verbose_name='领取标识', max_length=64, null=True, blank=True)
    p_max_number = models.IntegerField(verbose_name='限领最大数', default=0)
    p_take_number = models.IntegerField(verbose_name='占用领取数量', default=0)
    p_remain_number = models.IntegerField(verbose_name='剩余数量', default=0)
    p_use_number = models.IntegerField(verbose_name='已核销数量', default=0)
    p_receive_number = models.IntegerField(verbose_name='已领取数量', default=0)
    is_auth = models.SmallIntegerField(verbose_name='派发权限', choices=IS_AUTH_CHOICES, default=0, blank=True)

    class Meta:
        db_table = 'tb_ali_discount_coupon_level'
        verbose_name = '活动分配记录'
        verbose_name_plural = verbose_name


class AliDiscountCouponLevelRelation(models.Model):
    '''活动上下级'''

    parent = models.ForeignKey('vouchers.AliDiscountCouponLevel', verbose_name='上级', on_delete=models.CASCADE, related_name='parent_set')
    child = models.ForeignKey('vouchers.AliDiscountCouponLevel', verbose_name='下级', on_delete=models.CASCADE, related_name='child_set')

    class Meta:
        db_table = 'tb_ali_discount_coupon_level_relation'
        verbose_name = '活动上下级'
        verbose_name_plural = verbose_name


class AliDiscountCouponQRCode(models.Model):
    '''活动领取码'''

    QRCODE_STATE_CHOICES = (
        (1, '未使用'),
        (2, '已使用')
    )

    companyuser = models.ForeignKey('users.User', verbose_name='派发客户经理', on_delete=models.SET_NULL, null=True, blank=True)
    common_url = models.CharField(verbose_name='链接', max_length=128, null=True, blank=True)
    common_qrcode = models.ImageField(verbose_name='普码', null=True, blank=True)
    identify = models.CharField(verbose_name='领取标识', max_length=32, unique=True)
    alidiscountcoupon_level = models.ForeignKey(AliDiscountCouponLevel, verbose_name='所属地市活动', on_delete=models.SET_NULL, null=True, blank=True)
    qrcode_state = models.SmallIntegerField(verbose_name='二维码状态', choices=QRCODE_STATE_CHOICES, default=1, blank=True)
    out_biz_no = models.CharField(verbose_name='派发id', max_length=64, null=True, blank=True)
    gmt_distributed = models.DateTimeField(verbose_name='派发时间', null=True, blank=True)
    return_msg = models.CharField(verbose_name='失败原因', max_length=256, null=True, blank=True)

    class Meta:
        db_table = 'tb_ali_discount_coupon_qrcode'
        verbose_name = '活动领取码'
        verbose_name_plural = verbose_name


class AliDiscountCouponManagerQRCode(models.Model):
    '''活动领取码'''

    QRCODE_DIMENSION_CHOICES = (
        (1, '员工'),
        (2, '机构')
    )

    qrcode_dimension = models.SmallIntegerField(verbose_name='二维码维度', choices=QRCODE_DIMENSION_CHOICES, default=1, blank=True)
    companyuser = models.ForeignKey('users.User', verbose_name='派发客户经理', on_delete=models.SET_NULL, null=True, blank=True)
    level = models.ForeignKey('users.Level', verbose_name='派发机构', on_delete=models.SET_NULL, null=True, blank=True)
    common_url = models.CharField(verbose_name='链接', max_length=128, null=True, blank=True)
    common_qrcode = models.ImageField(verbose_name='普码', null=True, blank=True)
    identify = models.CharField(verbose_name='领取标识', max_length=48)
    alidiscountcoupon_level = models.ForeignKey(AliDiscountCouponLevel, verbose_name='所属地市活动', on_delete=models.SET_NULL, null=True, blank=True)
    alidiscountcoupon = models.ForeignKey('vouchers.AliDiscountCoupon', verbose_name='活动', on_delete=models.CASCADE)

    class Meta:
        db_table = 'tb_ali_discount_coupon_manager_qrcode'
        verbose_name = '活动领取码'
        verbose_name_plural = verbose_name


class AliDiscountCouponInfo(models.Model):
    '''券信息'''

    STATUS_CHOICES = (
        (0, '待领取'),
        (1, '待核销'),
        (2, '不可用'),
        (3, '已删除'),
        (4, '发送中'),
        (5, '已转增'),
        (6, '未领取'),
        (7, '已核销'),
        (8, '使用中'),
        (9, '已退款'),
        (10, '退款中'),
        (11, '待生效'),
        (12, '已过期'),
        (13, '已撤销'),
        (14, '领取失败')
    )

    STATUS_ENUM = {
        'ENABLED': 1,
        'DISABLED': 2,
        'DELETE': 3,
        'TRANS': 4,
        'TRANSFER': 5,
        'UNC': 6,
        'USED': 7,
        'USING': 8,
        'REFUNDED': 9,
        'REFUNDING': 10,
        'UNACTIVE': 11,
        'EXPIRED':  12
    }

    COUPON_CHANNEL_CHOICES = (
        (1, '支付宝'),
        (2, '微信'),
        (3, '商家')
    )

    alidiscountcoupon = models.ForeignKey(AliDiscountCoupon, verbose_name='所属地市活动', on_delete=models.CASCADE)
    alidiscountcoupon_level = models.ForeignKey(AliDiscountCouponLevel, verbose_name='所属地市活动', on_delete=models.SET_NULL, null=True, blank=True)
    voucher_id = models.CharField(verbose_name='券id', max_length=32, null=True, blank=True)
    user_id = models.CharField(verbose_name='用户id', max_length=32, null=True, blank=True)
    name = models.CharField(verbose_name='活动名称', max_length=32, null=True, blank=True)
    status = models.SmallIntegerField(verbose_name='券状态', choices=STATUS_CHOICES, default=1)
    template_id = models.CharField(verbose_name='券模板ID', max_length=32)
    gmt_active = models.DateTimeField(verbose_name='券激活时间', null=True, blank=True)
    gmt_expired = models.DateTimeField(verbose_name='券过期时间', null=True, blank=True)
    gmt_create = models.DateTimeField(verbose_name='券创建时间(即发券时间)', null=True, blank=True)
    gmt_use = models.DateTimeField(verbose_name='核销时间', null=True, blank=True)
    total_amount = models.DecimalField(verbose_name='券面额(元)' , max_digits=10, decimal_places=2, null=True, blank=True)
    available_amount = models.DecimalField(verbose_name='券余额(元)' , max_digits=10, decimal_places=2, null=True, blank=True)
    out_biz_no = models.CharField(verbose_name='派发id', max_length=64, null=True, blank=True)
    login_id = models.CharField(verbose_name='用户id', max_length=32, null=True, blank=True)
    aliuser = models.ForeignKey(AliAuthUser, verbose_name='所属用户', on_delete=models.SET_NULL, null=True, blank=True)
    aliflipcards = models.ForeignKey('vouchers.AliFlipCARDS', verbose_name='所属抽奖', on_delete=models.SET_NULL, null=True, blank=True)
    mobile = models.CharField(max_length=11, verbose_name='手机号', null=True, blank=True)
    companyuser = models.ForeignKey('users.User', verbose_name='派发客户经理', on_delete=models.SET_NULL, null=True, blank=True)
    customer_user = models.ForeignKey('users.CustomerUser', verbose_name='领取用户', on_delete=models.SET_NULL, null=True, blank=True)
    level = models.ForeignKey('users.Level', verbose_name='层级', on_delete=models.SET_NULL, null=True, blank=True)
    gmt_distributed = models.DateTimeField(verbose_name='派发时间', null=True, blank=True)
    gmt_undo = models.DateTimeField(verbose_name='撤销时间', null=True, blank=True)
    order = models.ForeignKey('orders.OrderInfo', verbose_name='占用订单', on_delete=models.SET_NULL, null=True, blank=True)
    appid = models.CharField(max_length=32, verbose_name='派发appid', null=True, blank=True)
    customeruservice = models.ForeignKey('users.CustomerUserVice', verbose_name='领取用户', on_delete=models.SET_NULL, null=True, blank=True)
    out_biz_order = models.CharField(verbose_name='订单号', max_length=64, null=True, blank=True)
    notify_url = models.CharField(verbose_name='回调url', max_length=256, null=True, blank=True)
    return_msg = models.CharField(verbose_name='失败原因', max_length=256, null=True, blank=True)
    mobile_bank_identify = models.CharField(verbose_name='手机银行唯一标识', max_length=64, null=True, blank=True)
    coupon_channel = models.SmallIntegerField(verbose_name='优惠券类型', choices=COUPON_CHANNEL_CHOICES, null=True, blank=True)
    merchantuser = models.ForeignKey('merchants.MerchantUser', verbose_name='领取用户', on_delete=models.SET_NULL, null=True, blank=True)

    class Meta:
        db_table = "tb_ali_discount_coupon_info"
        verbose_name = '优惠券信息'
        verbose_name_plural = verbose_name


class AliDiscountCouponInfoKeguan(models.Model):
    '''推送客管系统数据'''

    PUST_STATUS_CHOICES = (
        (1, '成功'),
        (2, '失败')
    )

    alidiscountcouponinfo = models.OneToOneField('vouchers.AliDiscountCouponInfo', verbose_name='派发数据', on_delete=models.CASCADE)
    push_status = models.SmallIntegerField(verbose_name='推送状态', choices=PUST_STATUS_CHOICES, default=1)
    push_time = models.DateTimeField(verbose_name='推送时间')
    return_msg = models.TextField(null=True, blank=True)

    class Meta:
        db_table = 'tb_ali_discount_coupon_info_keguan'
        verbose_name = '推送客管系统数据'
        verbose_name_plural = verbose_name


class AliDiscountCouponKeguanRecords(models.Model):
    '''推送客管系统数据操作记录'''

    OPERATE_TYPE_CHOICES = (
        (1, '开启'),
        (2, '关闭')
    )

    alidiscountcoupon = models.ForeignKey(AliDiscountCoupon, verbose_name='所属地市活动', on_delete=models.CASCADE)
    operate_time = models.DateTimeField(verbose_name='操作时间', auto_now_add=True)
    operate_user = models.ForeignKey('users.User', verbose_name='操作人', on_delete=models.CASCADE)
    operate_type = models.SmallIntegerField(verbose_name='操作类型', choices=OPERATE_TYPE_CHOICES, default=1)

    class Meta:
        db_table = 'tb_ali_discount_coupon_keguan_records'
        verbose_name = '推送客管系统数据操作记录'
        verbose_name_plural = verbose_name

class AliDiscountActivityCouponInfoKeGuanLog(models.Model):
    '''存量活动-推送客管系统数据'''

    PUST_STATUS_CHOICES = (
        (1, '成功'),
        (2, '失败')
    )

    activity = models.OneToOneField('vouchers.AliDiscountCoupon', verbose_name='活动id', on_delete=models.CASCADE)
    push_status = models.SmallIntegerField(verbose_name='推送状态', choices=PUST_STATUS_CHOICES, default=1)
    push_time = models.DateTimeField(verbose_name='推送时间')
    return_msg = models.TextField(null=True, blank=True)

    class Meta:
        db_table = 'tb_ali_discount_activity_coupon_keguan_log'
        verbose_name = '存量活动-推送客管系统数据'
        verbose_name_plural = verbose_name




class AliDiscountCouponInfoCampaignDrawcampTrigger(models.Model):
    '''营销抽奖活动触发抽奖'''

    voucherinfo = models.OneToOneField(AliDiscountCouponInfo, verbose_name='所属券', on_delete=models.CASCADE)
    result = models.TextField(verbose_name='响应结果')

    class Meta:
        db_table = "tb_ali_discount_coupon_info_campaign_drawcamp_trigger"
        verbose_name = '营销抽奖活动触发抽奖'
        verbose_name_plural = verbose_name


class AliDiscountCouponBillDetails(models.Model):
    '''券交易账单信息'''

    voucherinfo = models.ForeignKey(AliDiscountCouponInfo, verbose_name='所属券', on_delete=models.CASCADE)
    amount = models.DecimalField(verbose_name='券核销/退款金额(元)' , max_digits=10, decimal_places=2)
    biz_type = models.CharField(verbose_name='账单类型(V_USE:支付,V_REFUND:退款)', max_length=32)
    gmt_create = models.DateTimeField(verbose_name='交易时间')
    partner_id = models.CharField(verbose_name='交易合作伙伴ID', max_length=32, null=True, blank=True)
    partner_name = models.CharField(verbose_name='商户名称', max_length=32, null=True, blank=True)
    status = models.CharField(verbose_name='交易状态(I: 处理中, S: 成功)', max_length=16, null=True, blank=True)
    trade_no = models.CharField(verbose_name='支付宝交易号', max_length=64, null=True, blank=True)

    class Meta:
        db_table = "tb_ali_discount_coupon_bill_details"
        verbose_name = '券交易账单信息'
        verbose_name_plural = verbose_name


class AliFlipCARDS(models.Model):
    '''翻牌机会'''

    OPEN_STATUS_CHOICES = (
        (1, '初始状态'),
        (2, '中奖状态'),
        (3, '谢谢参与'),
        (4, '领取状态'),
        (5, '失效状态')
    )

    WIN_TYPE_CHOICES = (
        (1, '优惠券'),
        (2, '现金红包'),
        (3, '谢谢参与')
    )

    aliuser = models.ForeignKey(AliAuthUser, verbose_name='所属用户', on_delete=models.CASCADE)
    open_status = models.SmallIntegerField(verbose_name='卡牌状态', choices=OPEN_STATUS_CHOICES, default=1)
    identify = models.CharField(verbose_name='唯一标识', max_length=64)
    open_time = models.DateTimeField(verbose_name='翻牌时间', null=True, blank=True)
    gears = models.IntegerField(verbose_name='档位')
    alidiscountcoupon = models.ForeignKey(AliDiscountCoupon, verbose_name='是否中奖', on_delete=models.SET_NULL, null=True, blank=True)
    amount = models.DecimalField(verbose_name='中奖金额', max_digits=10, decimal_places=2, default=0)
    win_type = models.SmallIntegerField(verbose_name='卡牌状态', choices=WIN_TYPE_CHOICES, default=3)
    aliactivity = models.ForeignKey('vouchers.AliActivity', verbose_name='活动', on_delete=models.SET_NULL, null=True, blank=True)

    class Meta:
        db_table = 'tb_ali_flip_cards'
        verbose_name = '翻牌机会'
        verbose_name_plural = verbose_name


class AliFundTransfer(models.Model):
    '''支付宝转账记录'''

    TRANS_STATE_CHOICES = (
        (1, '已发起'),
        (2, '已到账')
    )

    trans_date = models.DateTimeField(verbose_name='转账时间', null=True, blank=True)
    order_id = models.CharField(verbose_name='支付宝转账订单号', max_length=64)
    out_biz_no = models.CharField(verbose_name='商户订单号', max_length=64)
    pay_fund_order_id = models.CharField(verbose_name='支付宝支付资金流水号', max_length=64, null=True, blank=True)
    order_title = models.CharField(verbose_name='业务标题', max_length=64)
    aliuser = models.ForeignKey(AliAuthUser, verbose_name='所属用户', on_delete=models.CASCADE)
    aliflipcards = models.ForeignKey('vouchers.AliFlipCARDS', verbose_name='所属抽奖', on_delete=models.CASCADE)
    pay_date = models.DateTimeField(verbose_name='进账时间', null=True, blank=True)
    trans_amount = models.DecimalField(verbose_name='转账金额', max_digits=10, decimal_places=2, default=0)
    trans_state = models.SmallIntegerField(verbose_name='转账进度', choices=TRANS_STATE_CHOICES, default=1)

    class Meta:
        db_table = 'tb_ali_fund_transfer'
        verbose_name = '支付宝转账记录'
        verbose_name_plural = verbose_name


class AliActivity(models.Model):
    '''活动'''

    ACTIVITY_STATE_CHOICES = (
        (1, '未开始'),
        (2, '进行中'),
        (3, '已暂停'),
        (4, '已结束')
    )

    available_begin_time = models.DateTimeField(verbose_name='开始时间', null=True, blank=True)
    available_end_time = models.DateTimeField(verbose_name='结束时间', null=True, blank=True)
    activity_state = models.SmallIntegerField(verbose_name='活动状态', choices=ACTIVITY_STATE_CHOICES, default=1, blank=True)
    lucky_count = models.IntegerField(verbose_name='抽奖次数')
    identify = models.CharField(verbose_name='唯一标识', max_length=64)

    class Meta:
        db_table = 'tb_ali_activity'
        verbose_name = '活动'
        verbose_name_plural = verbose_name


class AliActivityRules(models.Model):
    '''活动规则'''

    RULE_TYPE_CHOICES = (
        (1, '优惠券'),
        (2, '现金红包')
    )

    rule_type = models.SmallIntegerField(verbose_name='奖品类型', choices=RULE_TYPE_CHOICES, default=1, blank=True)
    count = models.IntegerField(verbose_name='数量')
    alidiscountcoupon = models.ForeignKey(AliDiscountCoupon, verbose_name='是否中奖', on_delete=models.SET_NULL, null=True, blank=True)
    amount_min = models.DecimalField(verbose_name='中奖金额范围(起)', max_digits=10, decimal_places=2, default=0)
    amount_max = models.DecimalField(verbose_name='中奖金额范围(止)', max_digits=10, decimal_places=2, default=0)
    aliactivity = models.ForeignKey('vouchers.AliActivity', verbose_name='活动', on_delete=models.SET_NULL, null=True, blank=True)

    class Meta:
        db_table = 'tb_ali_activity_rules'
        verbose_name = '活动规则'
        verbose_name_plural = verbose_name


class CustomizeActivity(models.Model):
    '''定制活动'''

    IS_NEED_AUTH_CHOICES = (
        (0, '否'),
        (1, '是')
    )

    ACTIVITY_STATUS_CHOICES = (
        (1, '进行中'),
        (2, '已结束'),
        (3, '未开始'),
        (4, '已暂停')
    )

    IS_WHITE_CHOICES = (
        (0, '否'),
        (1, '是')
    )

    ACTIVITY_TYPE_CHOICES = (
        (1, '随机抽奖'),
        (2, '大转盘抽奖(6扇)'),
        (4, '大转盘抽奖(8扇)'),
        (3, '随机码领取'),
        (5, '一分钱绑卡'),
        (6, '消费有礼'),
        (7, '周五膨胀抽奖'),
        (8, '超级大富翁'),
        (9, '商户推荐活动'),
        (10, '本对本'),
        (11, '员工派券包')
    )

    PRIZE_TYPE_CHOICES = (
        (1, '支付宝代金券'),
        (2, '微信代金券'),
        (3, '微信鼓励金'),
        (4, '谢谢参与'),
        (5, '积分'),
        (6, '支付宝鼓励金'),
        (7, '商家券'),
    )

    IS_BUSINESS_FORM_CHOICES = (
        (0, '否'),
        (1, '是')
    )

    IS_PSBC_CARD_CHOICES = (
        (0, '否'),
        (1, '是')
    )

    activity_id = models.CharField(verbose_name='活动名称', max_length=16, unique=True)
    create_user = models.ForeignKey('users.User', verbose_name='添加人', on_delete=models.CASCADE)
    activity_name = models.CharField(verbose_name='活动名称', max_length=32)
    activity_description = models.TextField(verbose_name='活动使用说明')
    activity_status = models.SmallIntegerField(verbose_name='活动状态', choices=ACTIVITY_STATUS_CHOICES, default=3, blank=True)
    activity_type = models.SmallIntegerField(verbose_name='活动类型', choices=ACTIVITY_TYPE_CHOICES, default=1, blank=True)
    prize_type = models.CharField(verbose_name='抽奖类型', max_length=8)
    is_need_auth = models.SmallIntegerField(verbose_name='是否需要认证', choices=IS_NEED_AUTH_CHOICES, default=1, blank=True)
    is_psbc_card = models.SmallIntegerField(verbose_name='是否需要验卡', choices=IS_PSBC_CARD_CHOICES, default=0, blank=True)
    create_time = models.DateTimeField(verbose_name='创建时间', auto_now_add=True)
    available_begin_time = models.DateTimeField(verbose_name='开始时间')
    available_end_time = models.DateTimeField(verbose_name='结束时间')
    is_white = models.SmallIntegerField(verbose_name='是否白名单派发', choices=IS_WHITE_CHOICES, default=0, blank=True)
    level = models.ForeignKey('users.Level', verbose_name='层级', on_delete=models.SET_NULL, null=True, blank=True)
    lucky_count_by_user = models.IntegerField(verbose_name='抽奖次数')
    total_count = models.IntegerField(verbose_name='抽奖次数')
    join_user_count = models.IntegerField(verbose_name='参与人次', default=0)
    identify = models.CharField(verbose_name='领取标识', max_length=64, unique=True)
    common_url = models.CharField(verbose_name='链接', max_length=128, null=True, blank=True)
    common_qrcode = models.ImageField(verbose_name='普码', null=True, blank=True)
    start_enable_time = models.DateTimeField(verbose_name='限时活动生效时间', null=True, blank=True)
    end_enable_time = models.DateTimeField(verbose_name='限时活动失效时间', null=True, blank=True)
    is_business_form = models.SmallIntegerField(verbose_name='是否需要填写业务表单', choices=IS_BUSINESS_FORM_CHOICES, default=0)
    is_draw_code = models.SmallIntegerField(verbose_name='是否兑奖码', choices=IS_BUSINESS_FORM_CHOICES, default=0)
    max_number = models.IntegerField(verbose_name='限领最大数', null=True, blank=True)
    take_number = models.IntegerField(verbose_name='占用领取数量', null=True, blank=True)
    remain_number = models.IntegerField(verbose_name='剩余数量', null=True, blank=True)
    drawdown_platform = models.ForeignKey('vouchers.AliDiscountCouponDistributionPlatform', verbose_name='领取平台', on_delete=models.SET_NULL, null=True, blank=True)

    class Meta:
        db_table = 'tb_customize_activity'
        verbose_name = '定制活动'
        verbose_name_plural = verbose_name


class CustomizeActivityPayRules(models.Model):

    IS_TOTAL_CHOICES = (
        (0, '否'),
        (1, '是')
    )

    IS_LIMIT_MERCHANT_CHOICES = (
        (0, '否'),
        (1, '是')
    )

    customizeactivity = models.OneToOneField('vouchers.CustomizeActivity', verbose_name='活动', on_delete=models.CASCADE)
    total_count = models.IntegerField(verbose_name='总交易笔数')
    amount = models.DecimalField(verbose_name='积分', max_digits=10, decimal_places=2, default=0)
    is_total = models.SmallIntegerField(verbose_name='是否完成全部', choices=IS_TOTAL_CHOICES, default=1)
    draw_counts = models.CharField(verbose_name='获奖次数', max_length=32)
    is_limit_merchant = models.SmallIntegerField(verbose_name='是否限制商户', choices=IS_LIMIT_MERCHANT_CHOICES, default=0)
    limit_merchant_count_by_day = models.IntegerField(verbose_name='每个商户有效交易笔数', null=True, blank=True)

    class Meta:
        db_table = 'tb_customize_activity_pay_rules'
        verbose_name = '定制活动(消费有礼规则)'
        verbose_name_plural = verbose_name


class CustomizeActivityPayRulesLimitMerchant(models.Model):

    merchant = models.ForeignKey('merchants.Merchant', verbose_name='商户', on_delete=models.CASCADE)
    customizeactivity = models.ForeignKey('vouchers.CustomizeActivity', verbose_name='活动', on_delete=models.CASCADE)

    class Meta:
        db_table = 'tb_customize_activity_pay_rules_limit_merchant'
        verbose_name = '定制活动(消费有礼规则)(限制商户)'
        verbose_name_plural = verbose_name


class CustomizeActivityLotteryRules(models.Model):

    IS_TOTAL_CHOICES = (
        (0, '否'),
        (1, '是')
    )

    FREE_LIMIT_CHOICES = (
        (1, '固定免费次数'),
        (2, '活动天数免费次数'),
        (3, '指定用户免费次数')
    )

    ACTIVITY_MODE_CHOICES = (
        (1, '活动期间有效'),
        (2, '活动期间固定时间有效')
    )

    IS_POINT_CHOICES = (
        (0, '否'),
        (1, '是')
    )

    customizeactivity = models.OneToOneField('vouchers.CustomizeActivity', verbose_name='活动', on_delete=models.CASCADE)
    point = models.DecimalField(verbose_name='一次消耗积分', max_digits=10, decimal_places=0, default=0)
    free_limit = models.SmallIntegerField(verbose_name='频率限制', choices=FREE_LIMIT_CHOICES, default=1, blank=True)
    join_limit_by_bay_count = models.IntegerField(verbose_name='每人每天领取个数限制', null=True, blank=True)
    join_limit_by_user_count = models.IntegerField(verbose_name='活动期间每个用户可参与限制', null=True, blank=True)
    activity_mode = models.SmallIntegerField(verbose_name='活动模式', choices=ACTIVITY_MODE_CHOICES, default=1)
    week_days = models.CharField(verbose_name='指定时间', max_length=32)
    start_enable_time = models.DateTimeField(verbose_name='限时活动生效时间')
    end_enable_time = models.DateTimeField(verbose_name='限时活动失效时间')
    is_point = models.SmallIntegerField(verbose_name='是否支持积分参与', choices=IS_POINT_CHOICES, default=1)

    class Meta:
        db_table = 'tb_customize_activity_lottery_rules'
        verbose_name = '定制活动(抽奖规则)'
        verbose_name_plural = verbose_name


class CustomizeActivityLotteryRulesUserFreeCount(models.Model):

    customizeactivity = models.ForeignKey('vouchers.CustomizeActivity', verbose_name='活动', on_delete=models.CASCADE)
    count = models.IntegerField(verbose_name='次数', default=0)
    customeruservice = models.ForeignKey('users.CustomerUserVice', verbose_name='所属用户', on_delete=models.CASCADE)

    class Meta:
        db_table = 'tb_customize_activity_lottery_rules_user_free_count'
        verbose_name = '定制活动(抽奖规则)指定用户免费次数'
        verbose_name_plural = verbose_name


class CustomizeActivityUserIndex(models.Model):
    '''大富翁活动用户记录'''

    customeruservice = models.ForeignKey('users.CustomerUserVice', verbose_name='所属用户', on_delete=models.CASCADE)
    customizeactivity = models.ForeignKey('vouchers.CustomizeActivity', verbose_name='活动', on_delete=models.CASCADE)
    index = models.IntegerField(verbose_name='位置号', default=52)
    create_time = models.DateTimeField(verbose_name='添加时间', auto_now_add=True)
    update_time = models.DateTimeField(verbose_name='更新时间', auto_now=True)

    class Meta:
        db_table = 'tb_customize_activity_user_index'
        verbose_name = '活动规则'
        verbose_name_plural = verbose_name


class CustomizeActivityRules(models.Model):
    '''活动规则'''

    PRIZE_TYPE_CHOICES = (
        (1, '支付宝代金券'),
        (2, '微信代金券'),
        (3, '微信鼓励金'),
        (4, '谢谢参与'),
        (5, '积分'),
        (6, '支付宝鼓励金'),
        (7, '商家券'),
        (8, '美团代金券')
    )

    IS_LIMIT_BY_DAY = (
        (0, '否'),
        (1, '是'),
        (None, '否')
    )

    prize_type = models.SmallIntegerField(verbose_name='奖品类型', choices=PRIZE_TYPE_CHOICES, default=1, blank=True)
    count = models.IntegerField(verbose_name='数量')
    alidiscountcoupon = models.ForeignKey(AliDiscountCoupon, verbose_name='是否中奖', on_delete=models.SET_NULL, null=True, blank=True)
    cashactivity = models.ForeignKey('cashbonus.CashActivity', verbose_name='是否中奖', on_delete=models.SET_NULL, null=True, blank=True)
    customizeactivity = models.ForeignKey('vouchers.CustomizeActivity', verbose_name='活动', on_delete=models.CASCADE)
    point = models.DecimalField(verbose_name='积分', max_digits=10, decimal_places=0, default=0)
    index = models.IntegerField(verbose_name='位置号', null=True, blank=True)
    icon = models.CharField(verbose_name='图标', null=True, blank=True, max_length=128)
    limit_by_day_count = models.IntegerField(verbose_name='每天领取个数限制', null=True, blank=True)
    is_limit_by_day = models.SmallIntegerField(verbose_name='是否每天领取个数限制', null=True, blank=True, choices=IS_LIMIT_BY_DAY)

    class Meta:
        db_table = 'tb_customize_activity_rules'
        verbose_name = '活动规则'
        verbose_name_plural = verbose_name


class CustomizeActivityFlipCARDS(models.Model):
    '''翻牌机会'''

    OPEN_STATUS_CHOICES = (
        (1, '初始状态'),
        (2, '待领取'),
        (3, '谢谢参与'),
        (4, '已领取'),
        (5, '失效状态'),
        (6, '领取失败')
    )

    WIN_TYPE_CHOICES = (
        (1, '支付宝代金券'),
        (2, '微信代金券'),
        (3, '微信鼓励金'),
        (4, '谢谢参与'),
        (5, '积分'),
        (6, '支付宝鼓励金'),
        (7, '商家券'),
        (8, '券包')
    )

    IS_FREE_CHOICES = (
        (0, '否'),
        (1, '是')
    )

    user = models.ForeignKey('users.CustomerUser', verbose_name='所属用户', on_delete=models.SET_NULL, null=True, blank=True)
    open_status = models.SmallIntegerField(verbose_name='卡牌状态', choices=OPEN_STATUS_CHOICES, default=1)
    identify = models.CharField(verbose_name='唯一标识', max_length=64, unique=True)
    open_time = models.DateTimeField(verbose_name='翻牌时间', null=True, blank=True)
    received_time = models.DateTimeField(verbose_name='领取时间', null=True, blank=True)
    pay_time = models.DateTimeField(verbose_name='交易时间', null=True, blank=True)
    gears = models.IntegerField(verbose_name='档位')
    alidiscountcoupon = models.ForeignKey(AliDiscountCoupon, verbose_name='是否中奖', on_delete=models.SET_NULL, null=True, blank=True)
    cashactivity = models.ForeignKey('cashbonus.CashActivity', verbose_name='是否中奖', on_delete=models.SET_NULL, null=True, blank=True)
    amount = models.DecimalField(verbose_name='中奖金额', max_digits=10, decimal_places=2, default=0)
    win_type = models.SmallIntegerField(verbose_name='卡牌状态', choices=WIN_TYPE_CHOICES, default=4)
    customizeactivity = models.ForeignKey('vouchers.CustomizeActivity', verbose_name='活动', on_delete=models.SET_NULL, null=True, blank=True)
    alidiscountcouponinfo = models.OneToOneField(AliDiscountCouponInfo, verbose_name='是否中奖', on_delete=models.SET_NULL, null=True, blank=True)
    cashactivitydata = models.OneToOneField('cashbonus.CashActivityData', verbose_name='是否中奖', on_delete=models.SET_NULL, null=True, blank=True)
    level = models.ForeignKey('users.Level', verbose_name='层级', on_delete=models.SET_NULL, null=True, blank=True)
    return_msg = models.TextField(null=True, blank=True)
    customeruservice = models.ForeignKey('users.CustomerUserVice', verbose_name='所属用户', on_delete=models.SET_NULL, null=True, blank=True)
    point = models.DecimalField(verbose_name='积分', max_digits=10, decimal_places=0, default=0)
    is_free = models.SmallIntegerField(verbose_name='是否免费', choices=IS_FREE_CHOICES, null=True, blank=True)
    mobile = models.CharField(verbose_name='手机号', max_length=11, null=True, blank=True)
    customizeactivityrules = models.ForeignKey(CustomizeActivityRules, verbose_name='中奖规则', on_delete=models.SET_NULL, null=True, blank=True)
    companyuser = models.ForeignKey('users.User', verbose_name='派发客户经理', on_delete=models.SET_NULL, null=True, blank=True)

    class Meta:
        db_table = 'tb_customize_activity_flip_cards'
        verbose_name = '翻牌机会'
        verbose_name_plural = verbose_name


class CustomizeActivityFlipCARDSDetail(models.Model):
    '''券包详情'''

    flipcard = models.ForeignKey('vouchers.CustomizeActivityFlipCARDS', verbose_name='翻牌', on_delete=models.CASCADE)
    alidiscountcouponinfo = models.OneToOneField(AliDiscountCouponInfo, verbose_name='是否中奖', on_delete=models.SET_NULL, null=True, blank=True)

    class Meta:
        db_table = 'tb_customize_activity_flip_cards_detail'
        verbose_name = '券包详情'
        verbose_name_plural = verbose_name


class CustomizeActivityWhiteTable(models.Model):
    '''活动参与白名单'''

    mobile = models.CharField(max_length=11, verbose_name='手机号')
    customizeactivity = models.ForeignKey('vouchers.CustomizeActivity', verbose_name='活动', on_delete=models.CASCADE)
    rule = models.ForeignKey('vouchers.CustomizeActivityRules', verbose_name='指定中奖', on_delete=models.SET_NULL, null=True, blank=True)

    class Meta:
        db_table = "tb_customize_activity_white_table"
        verbose_name = '活动参与白名单'
        verbose_name_plural = verbose_name


class CustomizeActivityLevel(models.Model):
    '''活动分配记录'''

    IS_AUTH_CHOICES = (
        (0, '无派发权限'),
        (1, '有派发权限')
    )

    level = models.ForeignKey('users.Level', verbose_name='层级', on_delete=models.CASCADE)
    customizeactivity = models.ForeignKey('vouchers.CustomizeActivity', verbose_name='活动', on_delete=models.CASCADE)
    common_url = models.CharField(verbose_name='链接', max_length=128, null=True, blank=True)
    common_qrcode = models.ImageField(verbose_name='普码', null=True, blank=True)
    identify = models.CharField(verbose_name='领取标识', max_length=64, unique=True)
    join_user_count = models.IntegerField(verbose_name='参与人次', default=0)
    max_number = models.IntegerField(verbose_name='限领最大数', null=True, blank=True)
    take_number = models.IntegerField(verbose_name='占用领取数量', null=True, blank=True)
    remain_number = models.IntegerField(verbose_name='剩余数量', null=True, blank=True)
    receive_number = models.IntegerField(verbose_name='已领取数量', null=True, blank=True)

    class Meta:
        db_table = 'tb_customize_activity_level'
        verbose_name = '活动分配记录'
        verbose_name_plural = verbose_name


class CustomizeActivityBusinessForm(models.Model):
    '''业务表单'''

    BUSINESS_TYPE_CHOICES = (
        (1, '定期'),
        (2, '活期'),
        (3, '长期期缴')
    )

    customizeactivityflipcards = models.OneToOneField('vouchers.CustomizeActivityFlipCARDS', verbose_name='奖励', on_delete=models.CASCADE)
    business_name = models.CharField(verbose_name='姓名', max_length=20)
    business_account = models.CharField(verbose_name='业务账号', max_length=4)
    business_amount = models.DecimalField(verbose_name='业务金额', max_digits=10, decimal_places=0, default=0)
    business_type = models.SmallIntegerField(verbose_name='业务类型', choices=BUSINESS_TYPE_CHOICES)

    class Meta:
        db_table = 'tb_customize_activity_business_form'
        verbose_name = '活动分配记录'
        verbose_name_plural = verbose_name


class CustomizeActivityPrizeDrawCode(models.Model):
    '''定制活动抽奖码'''

    customizeactivityflipcards = models.OneToOneField('vouchers.CustomizeActivityFlipCARDS', verbose_name='奖励', on_delete=models.SET_NULL, null=True, blank=True)
    customizeactivity = models.ForeignKey('vouchers.CustomizeActivity', verbose_name='活动', on_delete=models.CASCADE)
    draw_code = models.CharField(verbose_name='抽奖码', max_length=32)
    customeruser = models.ForeignKey('users.CustomerUser', verbose_name='所属用户', on_delete=models.SET_NULL, null=True, blank=True)
    customeruservice = models.ForeignKey('users.CustomerUserVice', verbose_name='所属用户', on_delete=models.SET_NULL, null=True, blank=True)
    customizeactivityrules = models.ForeignKey(CustomizeActivityRules, verbose_name='中奖规则', on_delete=models.SET_NULL, null=True, blank=True)

    class Meta:
        db_table = 'tb_customize_activity_prize_draw_code'
        verbose_name = '定制活动抽奖码'
        verbose_name_plural = verbose_name


class CustomizeActivityQRCode(models.Model):
    '''定制活动派发二维码'''

    QRCODE_STATE_CHOICES = (
        (1, '未使用'),
        (2, '已使用')
    )

    companyuser = models.ForeignKey('users.User', verbose_name='派发客户经理', on_delete=models.SET_NULL, null=True, blank=True)
    common_url = models.CharField(verbose_name='链接', max_length=128, null=True, blank=True)
    common_qrcode = models.ImageField(verbose_name='普码', null=True, blank=True)
    identify = models.CharField(verbose_name='领取标识', max_length=32, unique=True)
    customizeactivity_level = models.ForeignKey(CustomizeActivityLevel, verbose_name='所属地市活动', on_delete=models.SET_NULL, null=True, blank=True)
    qrcode_state = models.SmallIntegerField(verbose_name='二维码状态', choices=QRCODE_STATE_CHOICES, default=1, blank=True)
    out_biz_no = models.CharField(verbose_name='派发id', max_length=64, null=True, blank=True)
    gmt_distributed = models.DateTimeField(verbose_name='派发时间', null=True, blank=True)

    class Meta:
        db_table = 'tb_customize_activity_qrcode'
        verbose_name = '定制活动抽奖码'
        verbose_name_plural = verbose_name


class AliBizScene(models.Model):
    '''阿里活动可用场景'''

    fieldId = models.CharField(verbose_name='场景标识', max_length=32, null=True, blank=True)
    contents = models.TextField(verbose_name='说明', null=True, blank=True)

    class Meta:
        db_table = 'tb_ali_biz_scene'
        verbose_name = '阿里活动可用场景'
        verbose_name_plural = verbose_name


class UpdateStockUsableMerchant(models.Model):
    '''修改活动批次可用商户'''

    IS_ENTER_CHOICES = (
        (1, '处理中'),
        (2, '处理成功'),
        (3, '处理失败'),
        (4, '等待中'),
        (5, '已取消'),
        (6, '待审核')
    )

    ADD_TYPE_CHOICES = (
        (1, '文件'),
        (2, 'json')
    )

    IS_BLACK_CHOICES = (
        (0, '否'),
        (1, '是')
    )

    APPLY_STATES_CHOICES = (
        (1, '待审核'),
        (2, '审核通过'),
        (3, '审核不通过')
    )

    IS_WX_CHOICES = (
        (0, '否'),
        (1, '是')
    )

    user = models.ForeignKey('users.User', verbose_name='关联用户', on_delete=models.CASCADE)
    file = models.FileField(verbose_name='文件', null=True, blank=True)
    logs_file = models.FileField(verbose_name='日志文件', null=True, blank=True)
    remark = models.TextField(verbose_name='录入说明', null=True, blank=True)
    create_time = models.DateTimeField(verbose_name='添加时间', auto_now_add=True)
    wx_is_enter = models.SmallIntegerField(verbose_name='状态', choices=IS_ENTER_CHOICES, default=1)
    ylx_is_enter = models.SmallIntegerField(verbose_name='状态', choices=IS_ENTER_CHOICES, default=1)
    max_number = models.IntegerField(verbose_name='总数', default=0)
    wx_entry_number = models.IntegerField(verbose_name='录入数', default=0)
    ylx_entry_number = models.IntegerField(verbose_name='录入数', default=0)
    test = models.TextField(verbose_name='录入数据', null=True, blank=True)
    add_type = models.SmallIntegerField(verbose_name='新增类型', choices=ADD_TYPE_CHOICES, default=1)
    alidiscountcoupon = models.ForeignKey(AliDiscountCoupon, verbose_name='所属地市活动', on_delete=models.SET_NULL, null=True, blank=True)
    is_black = models.SmallIntegerField(verbose_name='是否校验黑名单', choices=IS_BLACK_CHOICES, default=1)
    apply_state = models.SmallIntegerField(verbose_name='申请单状态', choices=APPLY_STATES_CHOICES, default=2)
    return_msg = models.CharField(verbose_name='审核不通过原因', max_length=256, null=True, blank=True)
    is_wx = models.SmallIntegerField(verbose_name='是否提交微信', choices=IS_WX_CHOICES, default=1)
    is_ylx = models.SmallIntegerField(verbose_name='是否提交邮乐享', choices=IS_WX_CHOICES, default=1)
    line_number = models.IntegerField(verbose_name='行数', default=0)
    operation_user = models.ForeignKey('users.User', verbose_name='关联用户', on_delete=models.SET_NULL, null=True, blank=True, related_name='operation_user_set')
    operation_time = models.DateTimeField(verbose_name='添加时间', null=True, blank=True)

    class Meta:
        db_table = 'tb_update_stock_usable_merchant'
        verbose_name = '修改活动批次可用商户'
        verbose_name_plural = verbose_name


class BlackTable(models.Model):
    '''黑名单'''

    stock_id = models.CharField(verbose_name='批次号', max_length=32, unique=True)
    create_time = models.DateTimeField(verbose_name='添加时间', auto_now_add=True)
    create_user = models.ForeignKey('users.User', verbose_name='添加人', on_delete=models.CASCADE)

    class Meta:
        db_table = 'tb_black_table'
        verbose_name = '黑名单'
        verbose_name_plural = verbose_name


class AliDiscountCouponAPIRelation(models.Model):
    '''api派券归属'''

    create_user = models.ForeignKey('users.User', verbose_name='添加人', on_delete=models.CASCADE, related_name='create_user_set')
    developer = models.ForeignKey('users.User', verbose_name='开发者', on_delete=models.CASCADE, related_name='developer_set')
    alidiscountcoupon = models.ForeignKey(AliDiscountCoupon, verbose_name='所属地市活动', on_delete=models.CASCADE)

    class Meta:
        db_table = "tb_ali_discount_coupon_api_relation"
        verbose_name = 'api派券归属'
        verbose_name_plural = verbose_name


class AliDiscountCouponOperationRecord(models.Model):
    '''操作记录'''

    alidiscountcoupon = models.ForeignKey(AliDiscountCoupon, verbose_name='所属地市活动', on_delete=models.CASCADE)
    create_user = models.ForeignKey('users.User', verbose_name='添加人', on_delete=models.CASCADE)
    create_time = models.DateTimeField(verbose_name='操作时间', auto_now_add=True)
    remark = models.TextField(verbose_name='说明')

    class Meta:
        db_table = "tb_ali_discount_coupon_operation_record"
        verbose_name = '操作记录'
        verbose_name_plural = verbose_name


class AliDiscountCouponDistributionPlatform(models.Model):
    '''派发平台'''

    IS_VISIBLE_CHOICES = (
        (0, '否'),
        (1, '是')
    )

    platform_name = models.CharField(verbose_name='平台名称', max_length=64)
    is_visible = models.SmallIntegerField(verbose_name='是否删除', choices=IS_VISIBLE_CHOICES, default=1)

    class Meta:
        db_table = "tb_ali_discount_coupon_distribution_platform"
        verbose_name = '派发平台'
        verbose_name_plural = verbose_name


class AliDiscountCouponSyncWYHRecord(models.Model):
    '''微邮惠数据同步记录'''

    SYNC_STATUS_CHOICES = (
        (1, '处理中'),
        (2, '等待中'),
        (3, '已完成'),
        (4, '同步失败')
    )

    alidiscountcoupon = models.ForeignKey(AliDiscountCoupon, verbose_name='所属地市活动', on_delete=models.CASCADE)
    create_user = models.ForeignKey('users.User', verbose_name='添加人', on_delete=models.CASCADE)
    create_time = models.DateTimeField(verbose_name='操作时间', auto_now_add=True)
    sync_status = models.SmallIntegerField(verbose_name='状态', choices=SYNC_STATUS_CHOICES)
    remark = models.TextField(verbose_name='说明', null=True, blank=True)
    finish_time = models.DateTimeField(verbose_name='完成时间', null=True, blank=True)

    class Meta:
        db_table = "tb_ali_discount_coupon_sync_wyh_record"
        verbose_name = '微邮惠数据同步记录'
        verbose_name_plural = verbose_name


class AliDiscountCouponWYHRelevance(models.Model):
    '''公开派券活动关联'''

    template_id = models.CharField(verbose_name='券模板ID', max_length=32)
    activity_id = models.CharField(verbose_name='活动id', max_length=32)
    identification = models.CharField(verbose_name='确认id', max_length=32, unique=True)

    class Meta:
        db_table = "tb_ali_discount_coupon_wyh_relevance"
        verbose_name = '公开派券活动关联'
        verbose_name_plural = verbose_name


class CustomizeActivityBenBenOrder(models.Model):
    '''交易订单'''

    ORDER_TYPE_CHOICES = (
        (1, '微信'),
        (2, '支付宝'),
        (3, '云闪付'),
        (4, '本对本')
    )

    OPEN_STATUS_CHOICES = (
        (1, '初始状态'),
        (2, '待领取'),
        (3, '谢谢参与'),
        (4, '已领取'),
        (5, '失效状态'),
        (6, '领取失败')
    )

    program_id = models.CharField(verbose_name='应用id', max_length=18)
    unionid  = models.CharField(verbose_name='平台unionid', max_length=32)
    wyf_openid = models.CharField(verbose_name='微邮付⼩程序openid', max_length=32)
    shop_id = models.CharField(verbose_name='商户id', max_length=32)
    money = models.DecimalField(max_digits=10, decimal_places=2, verbose_name='支付金额', default=0)
    order_type = models.SmallIntegerField(verbose_name='订单类型', choices=ORDER_TYPE_CHOICES, default=1)
    out_trade_no = models.CharField(verbose_name='微邮付订单号', max_length=32, unique=True)
    pay_time = models.DateTimeField(verbose_name='支付时间')
    transaction_id = models.CharField(verbose_name='付款凭证中的条码单号', max_length=64)
    channel_trade_no = models.CharField(verbose_name='微信⽀付/云闪付单号', max_length=64)
    short_key = models.CharField(verbose_name='商户号', max_length=10)
    customeruservice = models.ForeignKey('users.CustomerUserVice', verbose_name='所属用户', on_delete=models.SET_NULL, null=True, blank=True)
    customizeactivityflipcards = models.OneToOneField('vouchers.CustomizeActivityFlipCARDS', verbose_name='奖励', on_delete=models.SET_NULL, null=True, blank=True)
    open_status = models.SmallIntegerField(verbose_name='卡牌状态', choices=OPEN_STATUS_CHOICES, default=1)

    class Meta:
        db_table = 'tb_customize_activity_benben_order'
        verbose_name = '本对本交易订单'
        verbose_name_plural = verbose_name


class AliDiscountCouponMerchantTable(models.Model):
    '''代金券添加商户白/黑名单'''

    IS_WHITE_CHOICES = (
        (0, '否'),
        (1, '是')
    )

    IS_BLACK_CHOICES = (
        (0, '否'),
        (1, '是')
    )

    business_no = models.CharField(verbose_name='商户号', max_length=10, null=True, blank=True)
    sub_mchid = models.CharField(verbose_name='微信间连商户号', max_length=10, unique=True)
    is_white = models.SmallIntegerField(verbose_name='是否白名单', choices=IS_WHITE_CHOICES, default=0)
    is_black = models.SmallIntegerField(verbose_name='是否黑名单', choices=IS_BLACK_CHOICES, default=0)
    white_create_time = models.DateTimeField(verbose_name='白名单添加时间', null=True, blank=True)
    black_create_time = models.DateTimeField(verbose_name='黑名单添加时间', null=True, blank=True)
    merchant = models.ForeignKey('merchants.Merchant', verbose_name='商户', on_delete=models.SET_NULL, null=True, blank=True)

    class Meta:
        db_table = "tb_ali_discount_coupon_merchant_table"
        verbose_name = '代金券添加商户黑名单'
        verbose_name_plural = verbose_name


class AliDiscountCouponMerchantTableHistory(models.Model):
    '''代金券添加商户名单历史'''

    ADD_TYPE_CHOICES = (
        (1, '追加'),
        (2, '覆盖'),
        (3, '删除')
    )

    ADD_STATE_CHOICES = (
        (1, '等待中'),
        (2, '处理中'),
        (3, '已处理'),
        (4, '处理失败')
    )

    DATA_TYPE_CHOICES = (
        (1, '文件'),
        (2, 'json')
    )

    TABLE_TYPE_CHOICES = (
        (1, '白名单'),
        (2, '黑名单')
    )

    create_user = models.ForeignKey('users.User', verbose_name='操作人', on_delete=models.CASCADE)
    file = models.FileField(verbose_name='文件', null=True, blank=True)
    create_time = models.DateTimeField(verbose_name='添加时间', auto_now_add=True)
    add_type = models.SmallIntegerField('添加类型', choices=ADD_TYPE_CHOICES, default=1)
    data_type = models.SmallIntegerField('数据类型', choices=DATA_TYPE_CHOICES, default=1)
    table_type = models.SmallIntegerField('名单类型', choices=TABLE_TYPE_CHOICES, default=1)
    add_state = models.SmallIntegerField('添加状态', choices=ADD_STATE_CHOICES, default=1)
    business_list = models.TextField(verbose_name='商户号列表', null=True, blank=True)
    remark = models.TextField(verbose_name='说明', null=True, blank=True)
    logs_file = models.FileField(verbose_name='日志文件', null=True, blank=True)

    class Meta:
        db_table = "tb_ali_discount_coupon_merchant_table_history"
        verbose_name = '代金券添加商户名单历史'
        verbose_name_plural = verbose_name

